package com.llmcu.source.java8.java8inaction.chapter12;

import java.time.Instant;
import java.time.temporal.ChronoField;

/**
 * Instant常用方法
 * @author liuling
 * @date 2024-12-16 16:36
 */
public class InstantDemo {
    public static void main(String[] args) {
        // 1. All the following invocations of the ofEpochSecond factory method will return exactly the same Instant
        Instant instant = Instant.ofEpochSecond(3, 0);
        Instant instant1 = Instant.ofEpochSecond(4, -1_000_000_000);
        Instant instant2 = Instant.ofEpochSecond(2, 1_000_000_000);
        Instant instant3 = Instant.ofEpochSecond(5, -2_000_000_000);
        System.out.println(instant);
        System.out.println(instant1);
        System.out.println(instant2);
        System.out.println(instant3);

        // 2. now()方法创建对象
        Instant now = Instant.now();

        // a. It doesn’t provide any ability to handle units of time that are meaningful to humans.
        Instant.now().get(ChronoField.DAY_OF_MONTH);

    }
}
